﻿// -----------------------------------------------------------------------
// <copyright file="AssemblyInitializeAndCleanup.cs">
// Copyright (c) 2013-2014 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com  andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace FileWarehouse.Azure.UnitTests
{
    using System;
    using System.Diagnostics;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.WindowsAzure;
    using Microsoft.WindowsAzure.Storage;

    [TestClass]
    public class AssemblyInitializeAndCleanup
    {
        [AssemblyInitialize]
        public static void AssemblyInitialize(TestContext context)
        {
            var count = Process.GetProcessesByName("WAStorageEmulator").Length;

            if (count == 0)
                throw new Exception("Windows Azure Storage Emulator is not running.");
        }

        [AssemblyCleanup]
        public static void TestCleanup()
        {
            // Get blob client
            var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(StorageConsts.ConnectionStringName));
            var blobClient = storageAccount.CreateCloudBlobClient();

            // Remove all test containers
            var testContainers = blobClient.ListContainers(StorageConsts.ContainerNamesPrefix).ToArray();
            foreach (var container in testContainers) {
                container.DeleteIfExists();
            }
        }
    }
}
